package com.xyy.saas.payment.job.syncData;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.xyy.elasticjob.client.annotation.ElasticJobConf;
import com.xyy.saas.payment.pojo.param.PayAmountReportParam;
import com.xyy.saas.payment.service.job.OrderJobService;
import com.xyy.saas.payment.util.JSONUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;
import java.util.Date;

@ElasticJobConf(name = "xyy.elastic.job.manage.payAmountReport-2—yesterday", cron = "0 0 2 * * ?")
public class PayAmountReportJob  implements SimpleJob {

    private static final Logger LOGGER =  LoggerFactory.getLogger(PayAmountReportJob.class);

    @Autowired
    private OrderJobService orderJobService;

    @Override
    public void execute(ShardingContext shardingContext) {
        LOGGER.info("PayAmountReportJob#execute start. shardingContext:{}", JSONUtils.toJSON(shardingContext));
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1);
        Date yesterday = calendar.getTime();
        PayAmountReportParam param = new PayAmountReportParam();
        param.setStartTime(yesterday);
        param.setEndTime(yesterday);
        orderJobService.syncPayAmountReport(param);
        LOGGER.info("PayAmountReportJob#execute end.");
    }
}
